package com.zhang.controller;

import com.auth0.jwt.JWT;
import com.zhang.pojo.Result;
import com.zhang.utils.JwtUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/kucun")
public class KuCunGuanLiController {

    //当前库存查询
    @GetMapping("/list")
    public Result<String> dangQianKuCun(/*@RequestHeader(name = "Authorization") String token, HttpServletResponse response*/){

/*        //验证token,并接受载荷中的业务数据id、username
        //try：验证通过 catch：验证失败  （Ctrl+Alt+T 快速生成try catch）
        try {
            Map<String, Object> clamis = JwtUtil.parseToken(token);
            return Result.success("所有库存数据！");
        } catch (Exception e) {
            //将响应状态码改为401，标识失败
            response.setStatus(401);
            System.out.println(e.getMessage());
            return Result.error("未登录");
        }*/
        return Result.success("所有库存数据");
    }

/*    //当前库存查询
    @GetMapping("/list")
    public Result<String> dangQianKuCun(HttpServletRequest request, HttpServletResponse response){

        //验证token,并接受载荷中的业务数据id、username
        //try：验证通过 catch：验证失败  （Ctrl+Alt+T 快速生成try catch）

        String token = request.getHeader("Authorization");
        System.out.println("token"+token);
        try {
            Map<String, Object> clamis = JwtUtil.parseToken(token);
            return Result.success("所有库存数据！");
        } catch (Exception e) {
            //将响应状态码改为401，标识失败
            response.setStatus(401);
            System.out.println(e.getMessage());
            return Result.error("未登录");
        }
        *//*        return Result.success("所有库存数据");*//*
    }*/
}
